Skip to content

fix(client): time out requests after the handshake (#474) - #505

Merged
lxsaah merged 3 commits into
mainfrom
fix/client-request-timeout-474
Nov 26, 2026
Merged

lxsaah merged 3 commits into
mainfrom
fix/client-request-timeout-474

Conversation

@lxsaah

@lxsaah lxsaah commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Closes #474.

Problem

AimxConnection bounded only the hello handshake. Every later request awaited its reply forever, so aimdb record get/set and the MCP tools hung on an instance that stopped answering mid-session (hung task, board held by a watchdog, link dropped without closing).

Changes

aimdb-client

  • Every typed call that awaits a reply (get_record, set_record, list_records, drain_record*, query, graph_*, instance_info, each post_link chunk, the resets) is bounded by a per-connection request timeout: engine::DEFAULT_REQUEST_TIMEOUT (5 s), configurable via AimxConnection::with_request_timeout.
  • A timeout fails with the new ClientError::Timeout { method, after }. The connection stays open; the engine already sweeps abandoned pending calls and discards late replies.
  • Not bounded: subscribe, write_record, raw handle().call(…).

aimdb-cli

  • New global --request-timeout <SECS> (default 5, min 1), threaded through a small Target { endpoint, request_timeout } struct.
  • A timeout exits 3 (environment, worth retrying), keeping 4 for watch --timeout.
  • Named --request-timeout rather than the issue's --timeout: a global --timeout would clash with watch --timeout, which means something different.

aimdb-mcp

  • Picks up the default, so a silent instance no longer holds the client lock indefinitely.
  • A ClientError::Timeout from a tool is returned as a tool error (isError: true, text naming the method), as the issue proposes, so the agent can retry or report the instance as unresponsive. All other errors remain JSON-RPC errors as before; extending that to every client error is a follow-up.

Notes for review

  • Adding a ClientError variant is breaking for exhaustive matches (the enum isn't #[non_exhaustive]), so aimdb-client needs a minor bump.
  • Verified locally with Rust 1.97 + --ignore-rust-version (the pinned 1.98 couldn't be downloaded in my environment): tests, clippy -D warnings and fmt pass for aimdb-client, aimdb-cli and aimdb-mcp. CI on 1.98 should confirm.

Tests

  • aimdb-client/tests/request_timeout.rs: fake server answers hello then goes silent; a typed call and instance_info both fail with ClientError::Timeout, and the connection still serves a request afterwards.
  • aimdb-cli error::tests::exit_codes_follow_failure_classes: a client timeout maps to exit 3.
  • aimdb-mcp server::tests::a_request_timeout_is_a_tool_error: timeout → isError: true; success and other errors unchanged.

https://claude.ai/code/session_01WGkDJ9zFEC4MLmEkzF8fiE


Generated by Claude Code

AimxConnection bounded only the `hello` handshake; every later request
awaited its reply forever, so `aimdb record get/set` and the MCP tools
hung on an instance that stopped answering mid-session.

- aimdb-client: each reply-awaiting call is bounded by a per-connection
  request timeout (DEFAULT_REQUEST_TIMEOUT, 5 s; set with
  `with_request_timeout`) and fails with the new `ClientError::Timeout`.
  The connection stays open; the engine reclaims the abandoned call and
  discards a late reply. Subscriptions and `write_record` are unbounded.
- aimdb-cli: global `--request-timeout <SECS>` (default 5, min 1). A
  timeout exits 3 (environment, worth retrying). Named so it does not
  clash with `watch --timeout`.
- aimdb-mcp: picks up the default, so a silent instance returns a tool
  error instead of holding the client lock indefinitely.

Closes #474

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGkDJ9zFEC4MLmEkzF8fiE
The previous commit's changelog entry for aimdb-mcp described behaviour
the crate got only through the client default. Make the MCP side do what
the issue asks: a ClientError::Timeout from a tool now returns a
ToolCallResult with isError: true and a message naming the method, so
the agent can retry or report the instance as unresponsive. Other
errors remain JSON-RPC errors as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGkDJ9zFEC4MLmEkzF8fiE
- aimdb-cli: replace the end-to-end silent-server test with one entry in
  the existing exit-code unit test (ClientError::Timeout -> exit 3); drop
  the clap range test.
- aimdb-client: keep one typed call, one `not_found`-as-answer call
  (instance_info) and the still-open check; drop the redundant calls,
  the default-value assert, the elapsed-time bound and the message match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGkDJ9zFEC4MLmEkzF8fiE
@lxsaah
lxsaah merged commit 8efa30b into main Nov 26, 2026
10 checks passed
@lxsaah
lxsaah deleted the fix/client-request-timeout-474 branch November 26, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aimdb-client: requests after the handshake have no timeout; the CLI hangs on a silent instance

2 participants